<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>链接转换器</title>
    <link rel="stylesheet" href="./reset.css">
    <style>
        body {
            /* display: flex;
            justify-content: center;
            align-items: flex-start;
            margin: 20px; */
        }

        textarea,
        .output {
            width: 50%;
            height: 800px;
            margin: 10px;
            padding: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        .output {
            background-color: #f9f9f9;
            overflow-y: auto;
        }

        .output a {
            font-size: 18px;
            line-height: 30px;
        }

        .container {
            display: flex;
        }

        .button-container {
            text-align: center;
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div class="container flex jc-c">
        <textarea id="inputLinks" placeholder="输入多个链接，每行一个"></textarea>
        <div class="output" id="outputLinks"></div>
    </div>
    <div class="button-container flex jc-ai-c">
        <button onclick="convertLinks()">转换</button>
    </div>
    <script>
        function convertLinks() {
            const inputText = document.getElementById('inputLinks').value;
            const lines = inputText.split('\n');
            let outputHtml = '';
            lines.forEach(line => {
                if (line.trim()) {
                    outputHtml += `
                        <a href="${line.trim()}" target="_blank">${line.trim()}</a>
                        <button class="copy-button" onclick="copyLink('${line.trim()}')">复制</button>
                        <br>
                    `;
                }
            });
            document.getElementById('outputLinks').innerHTML = outputHtml;
        }

        function copyLink(link) {
            navigator.clipboard.writeText(link).then(function () {
                // alert("链接已复制到剪贴板");
            }, function (err) {
                console.error('Async: Could not copy text: ', err);
            });
        }
    </script>
</body>

</html>